package com.usian.search.controller.v1;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.usian.common.dtos.ResponseResult;
import com.usian.common.threadlocal.UserThreadLocalUtils;
import com.usian.model.search.dtos.UserSearchDto;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.search.service.IApUserSearchService;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP用户搜索信息表 前端控制器
 * </p>
 *
 * @author usian
 * @since 2022-10-19
 */
@RestController
@RequestMapping("/api/v1/history")
@Api(tags = "APP用户搜索信息表接口")
@CrossOrigin
public class ApUserSearchController{

    @Autowired
    private IApUserSearchService apUserSearchService;


    /**
     * 查询用户的搜索关键词
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult<Set<String>> findUserSearch(@RequestBody UserSearchDto dto){
        Integer userId = UserThreadLocalUtils.getUserId();
        Set<String> userSearch = apUserSearchService.findUserSearch(dto, userId);
        return ResponseResult.ok(userSearch);
    }

    /**
     * 删除用户的搜索关键词
     * @param dto
     * @return
     */
    @PostMapping("/del")
    public ResponseResult removeUserSearch(@RequestBody UserSearchDto dto){
        Integer userId = UserThreadLocalUtils.getUserId();
        apUserSearchService.removeUserSearch(dto,userId);
        return ResponseResult.ok();
    }

}
